﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq.Expressions;
using CodeContrib.Data.Entity;

namespace CodeContrib.Tests.Data.Entity
{
	public class CustomTree : CodeContrib.Data.Entity.Entity, ITree<CustomTreeNode> //Tree<CustomTreeNode>
	{
		public string Name { get; set; }

		private ICollection<CustomTreeNode> TreeNodes { get; set; }

		public CustomTree()
		{
			TreeNodes = new Collection<CustomTreeNode>();
		}

		public CustomTreeNode AddRootNodeIfNotExists()
		{
			return TreeNodes.AddRootNodeIfNotExists();
		}

		public TreeNode AddTreeNode(int parenTreeNodeId)
		{
			return TreeNodes.AddTreeNode(parenTreeNodeId);
		}

		public CustomTreeNode AddTreeNodeToRoot()
		{
			return TreeNodes.AddTreeNodeToRoot();
		}

		public void RemoveTreeNode(int treeNodeId)
		{
			TreeNodes.RemoveTreeNode(treeNodeId);
		}

		public CustomTreeNode Root()
		{
			return TreeNodes.Root();
		}

		public TreeHierarchy<CustomTreeNode> ToHierarchy()
		{
			return TreeNodes.ToHierarchy();
		}

		public class PropertyAccessExpressions
		{
			public static Expression<Func<CustomTree, ICollection<CustomTreeNode>>> _treeNodes;

			public static Expression<Func<CustomTree, ICollection<CustomTreeNode>>> TreeNodes
			{
				get { return _treeNodes; }
			}

			static PropertyAccessExpressions()
			{
				_treeNodes = x => x.TreeNodes;
			}
		}
	}

	//public class CustomTree : Tree<CustomTreeNode>
	//{
	//}
}